<template>
  <el-drawer v-model="addDrawer" size="48%" :show-close="false" @opened="openDrawer" @close="closeDrawer">
    <template #title>
      <h2><svg-icon icon-class="list"></svg-icon><span style="padding-left: 15px">{{ typeName }}</span></h2>
      <el-button type="primary" @click="confirmClick" :disabled="drawerLoading" v-if="isShowSave">保存</el-button>
    </template>
    <template #default>
      <el-form :model="form" ref="addRef" :inline="true" :rules="formRules" label-width="160px" v-loading="drawerLoading">
        <el-row justify="space-between">
          <el-form-item label="省">
            <el-input v-model="form.province" clearable disabled></el-input>
          </el-form-item>
          <el-form-item label="市">
            <el-input v-model="form.city" clearable disabled></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="区/县">
            <el-input v-model="form.county" clearable disabled></el-input>
          </el-form-item>
          <el-form-item label="强震事件编号" prop="id">
            <el-input v-model="form.id" placeholder="请输入强震事件编号" clearable maxlength="17"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="日期" prop="occurrenceDate">
            <el-input v-model="form.occurrenceDate" placeholder="请输入日期" clearable maxlength="20" />
          </el-form-item>
          <el-form-item label="发震时间" prop="occurrenceTime">
            <el-input v-model="form.occurrenceTime" placeholder="请输入发震时间"  clearable maxlength="20"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="地名" prop="locationName" style="width: 100%">
            <el-input v-model="form.locationName" placeholder="请输入地名" :autosize="{ minRows: 2, maxRows: 4 }"
              type="textarea" show-word-limit maxlength="40" clearable></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="经度" prop="lon">
            <el-input v-model="form.lon" placeholder="请输入经度" clearable maxlength="8"></el-input>
          </el-form-item>
          <el-form-item label="纬度" prop="lat">
            <el-input v-model="form.lat" placeholder="请输入纬度" clearable maxlength="8"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="震级 [M]" prop="magnitude">
            <el-input v-model="form.magnitude" placeholder="请输入震级 [M]" clearable maxlength="8"></el-input>
          </el-form-item>
          <el-form-item label="震源深度 [公里]" prop="depth">
            <el-input v-model="form.depth" placeholder="请输入震源深度 [公里]" clearable maxlength="8"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="宏观震中烈度" prop="epicenter">
            <el-input v-model="form.epicenter" placeholder="请输入宏观震中烈度" clearable maxlength="20"></el-input>
          </el-form-item>
          <el-form-item label="精度" prop="accuracy">
            <el-input v-model="form.accuracy" placeholder="请输入精度" clearable maxlength="2"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="等震线图图表编号" prop="ilGraphAiid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.ilGraphAiid" placeholder="请输入等震线图图表编号" clearable maxlength="20"></el-input>
              <ImageUpload v-model="form.ilGraphAiidName" @uploadImage="uploadSuccess('ilGraphAiid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="等震线图原始图表编号" prop="ilGraphArwid" style="width:100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.ilGraphArwid" placeholder="请输入等震线图原始图表编号" clearable maxlength="20"></el-input>
              <FileUpload v-model="form.ilGraphArwidName" @uploadFile="uploadSuccess('ilGraphArwid', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="符号或标注旋转角度" prop="lastAngle">
            <el-input v-model="form.lastAngle" placeholder="请输入符号或标注旋转角度" clearable maxlength="8"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="备注" prop="commentInfo" style="width:100%">
            <el-input v-model="form.commentInfo" placeholder="请输入备注" :autosize="{ minRows: 6, maxRows: 12 }"
              type="textarea" show-word-limit maxlength="2147483647" clearable></el-input>
          </el-form-item>
        </el-row>
      </el-form>
    </template>
  </el-drawer>
</template>
<script setup>
import useSpatialData from '@/hooks/useSpatialData'
import { eightDouble } from '@/utils/validate'
const { route, addDrawer, drawerLoading, form, typeName, openDrawer, closeDrawer, confirmClick, uploadSuccess, deleteFile, isShowSave } = useSpatialData()
const formRules = {
  id: [{ required: true, message: '请填写强震事件编号！', trigger: 'blur' }],
  occurrenceDate: [{ required: true, message: '请填写日期！', trigger: 'blur' }],
  lon: [{ required: true, message: '请填写经度！', trigger: 'blur' }, eightDouble],
  lat: [{ required: true, message: '请填写纬度！', trigger: 'blur' }, eightDouble],
  magnitude: [{ required: true, message: '请填写震级 [M]！', trigger: 'blur' }, eightDouble],
  depth: [eightDouble],
  accuracy: [{ pattern: /^([0]|[1-9][0-9]{0,1})?$/, message: '请输入正确的不超过2位的整数!', trigger: 'blur' }],
  lastAngle: [eightDouble]
}
</script>
<style scoped></style>